<?php
    session_start();
    require_once '../includes/runtime/lib/Propel.php';
    Propel::init("../includes/build/conf/easylib-conf.php");
    set_include_path("../includes/build/classes" . PATH_SEPARATOR . get_include_path());
    $stations = TabStationQuery::create()->find();
    $results = array();
    foreach($stations as $station){
        $station instanceof TabStation;
        $infostation=  TabInformationStationQuery::create()->filterByFkStation($station->getIdStation())->orderByLastUpdate(Criteria::DESC)->findOne();
        if($infostation != NULL){
            $results[]=array(
                'IdStation' => $station->getIdStation(),
                'StationAddress' => $station->getStationAddress(),
                'StationLatitude' => $station->getStationLatitude(),
                'StationLongitude' => $station->getStationLongitude(),
                'LastUpdate' => $infostation->getLastUpdate($format='d-m-Y H:i:s'),
                'Bonus' => $infostation->getBonus(),
                'AvailableBikes' => $infostation->getAvailableBikes(),
                'AvailableBikeStands' => $infostation->getAvailableBikeStands()
            );
        }
    }
    echo json_encode($results);  
?>
